package logic

import (
	"context"
	"module-name/api/internal/svc"
	"module-name/api/internal/types"
	"module-name/modulerpc/modulerpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopCarLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewShopCarLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopCarLogic {
	return &ShopCarLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ShopCarLogic) ShopCar(req *types.ShopCarRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.ModuleRpc.ShopCar(l.ctx, &modulerpc.ShopCarRequest{
		UserId: int64(req.UserId),
		ProId:  int64(req.ProId),
		Stock:  int64(req.Stock),
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "添加成功",
		Data:    add,
	}, nil
	return
}
